package test;

import java.lang.reflect.Proxy;

public  class JdkProxyDemo {
     interface  Interface{
        void study();
        void introduce();
    }
    static  class Target implements Interface{
        @Override
        public void study() {
            System.out.println("我在study...");
        }

        @Override
        public void introduce() {
            System.out.println("我是target...");
        }
        //基于JDK的动态代理
    }
    public static void main(String[] args) {
        Target target = new Target();
        ClassLoader loader = JdkProxyDemo.class.getClassLoader();
        Interface proxyInstance =(Interface) Proxy.newProxyInstance(loader, new Class[]{Interface.class}, ((proxy, method, args1) -> {
            System.out.println("前置增强...");
            method.invoke(target,args1);//反射
            System.out.println("后置增强...");
            return null;
        }));
        proxyInstance.study();
    }
}
